package com.sp.scmdb.action;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sp.scmdb.bean.ManulOutWellBean;
import com.sp.scmdb.bean.UserBean;
import com.sp.scmdb.common.action.BaseAction;
import com.sp.scmdb.service.EmployeeService;
import com.sp.scmdb.service.MonitorService;

@Controller("manulOutWellAction")
@Scope("prototype")
public class ManulOutWellAction extends BaseAction<ManulOutWellBean> {

	private static final long serialVersionUID = 1L;
	private static Log log = LogFactory.getLog(ManulOutWellAction.class);
	
	private MonitorService monitorService;
	private EmployeeService empService; 

	@SuppressWarnings("unchecked")
	public String findAll(){
		try{
			UserBean user = (UserBean)session.get("user");	
			entity.setListDept(empService.getListDepartment(user));
			
			ManulOutWellBean bean = null;
			if (StringUtils.isNotEmpty(pageName)) {
				bean = (ManulOutWellBean)session.get("ManulOutWellBean");
			}
			
			entity.setAllList(monitorService.allEmpShow(user, entity, bean));
			entity.setList(entity.getAllList().subList(entity.getCurrentRow(), entity.getLastRow()));
			
			session.put("ManulOutWellBean", entity);
			
		} catch(RuntimeException e){
			log.error("findAll fail!reason:" + e.getMessage());
			return "fail";
		} catch(Exception e){
			log.error("findAll fail!reason:" + e.getMessage());
			return "error";
		}
		return SUCCESS;
	}
	
	public String initManulOutWell(){

		UserBean user = (UserBean)session.get("user");		
		entity.setListDept(empService.getListDepartment(user));
		
		return SUCCESS;
	}
	
	public String manulOutWell(){
		String empID = request.getParameter("empID");
		String flg = monitorService.manulOutWell(empID);
		if ("0".equals(flg)) {
			messageSession("0", "操作成功！");
		} else {
			messageSession("0", "操作失败！");
		}
		
		return "commitSucc";
	}
	
	public void setEmpService(EmployeeService empService) {
		this.empService = empService;
	}
	
	public void setMonitorService(MonitorService monitorService) {
		this.monitorService = monitorService;
	}
	
}
